<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./template.js"></script>
</head>

<body>
    <div class="user-box"></div>
    <script type="text/html" id="tpl-user">
        <div>姓名：{{name}}</div>
        <div>年龄：{{ age }}</div>
        <div>性别：{{ gender}}</div>
        <div>住址：{{address }}</div>
    </script>
    <script>
        // 定义数据
        var data = {
            name: 'zs',
            age: 28,
            gender: '男',
            address: '北京'
        }

        // 调用模板引擎
        var htmlStr = template('tpl-user', data);
        // 渲染html结构
        document.querySelector('.user-box').innerHTML = htmlStr;
    </script>
</body>

</html>